package com.zhai.cloud.starter.snowflake.config;

import com.zhai.cloud.starter.snowflake.prop.SnowflakeProperties;
import com.zhai.cloud.starter.snowflake.work.SnowflakeWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Created by 翟凤玺
 * @package com.zhai.cloud.starter.snowflake.config
 * @project-name zhai-cloud
 * @description 自动配置
 * @create-datetime 2019-11-26 16:08
 */
@Configuration
@ConditionalOnClass(SnowflakeWorker.class)
@EnableConfigurationProperties(SnowflakeProperties.class)
public class SnowflakeConfig {

    @Autowired
    SnowflakeProperties snowflakeProperties;

    @Bean
    @ConditionalOnMissingBean
    SnowflakeWorker snowflakeWorker() {
        return new SnowflakeWorker(snowflakeProperties.getWorkerId(), snowflakeProperties.getDatacenterId());
    }
}